#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <SDL/SDL.h>

#include "display.h"
#include "fonts_gfx.h"

SDL_Surface *font;

void drawchar(char ch, int x, int y)
{
    SDL_Rect src, dst;
    
    src.w=7; src.h=12;
    src.x=0;  src.y=(ch-32)*12;

    dst.w=7; dst.h=12;
    dst.x=x;  dst.y=y;
    
    SDL_BlitSurface(font,&src,screen,&dst);
}

void drawtext(const char *string, int x, int y)
{
    while(*string)
    {
        drawchar(*string,x,y);
        x+=7;
        string++;
    }
}

void initfont()
{
    SDL_Surface *temp;
    SDL_RWops *rw;

    // read bitmap binary stream
    rw=SDL_RWFromConstMem(fonts_bmp,sizeof(fonts_bmp));
    temp=SDL_LoadBMP_RW(rw,1); // automatically free RWops
    
    font=SDL_ConvertSurface(temp,screen->format,SDL_SWSURFACE);
    SDL_FreeSurface(temp);

    // apply color mask
    SDL_SetColorKey(font,SDL_SRCCOLORKEY,0xff00ff);
}